package x.trident.core.config.center.listener;

import lombok.SneakyThrows;
import org.springframework.boot.context.event.ApplicationContextInitializedEvent;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import x.trident.core.config.center.context.NacosConfigContext;
import x.trident.core.listener.ContextInitializedListener;

/**
 * 启动的时候初始化NacosClient
 *
 * @author 林选伟
 * @date 2021/9/3 11:26 上午
 */
public class NacosClientListener extends ContextInitializedListener implements Ordered {
    @Override
    public int getOrder() {
        return Ordered.HIGHEST_PRECEDENCE + 200;
    }

    @SneakyThrows
    @Override
    public void eventCallback(ApplicationContextInitializedEvent event) {
        // 获取environment参数
        ConfigurableEnvironment environment = event.getApplicationContext().getEnvironment();
        NacosConfigContext.initConfigService(environment);

    }
}
